<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <cpn v-bind:number1="num1"
         v-bind:number2="num2"
         @child-num1-change="parentNum1Change"
         @child-num2-change="parentNum2Change"></cpn>
</div>

<template id="cpn">
    <div>
        <h2>props:{{number1}}</h2>
        <h2>data:{{dnumber1}}</h2>
<!--        <input type="text" v-model="dnumber1">-->
        <input type="text" v-bind:value="dnumber1" v-on:input="childNum1Input">
        <h2>props:{{number2}}</h2>
        <h2>data:{{dnumber2}}</h2>
<!--        <input type="text" v-model="dnumber2">-->
        <input type="text" v-bind:value="dnumber2" v-on:input="childNum2Input">
    </div>
</template>
<script src="../js/vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            num1: 1,
            num2: 2
        },
        components: {
            cpn: {
                template: '#cpn',
                props: {
                    number1: {
                        type: Number,
                        default(){
                            return 'default'
                        }
                    },
                    number2: {
                        type: Number,
                        default() {
                            return "default";
                        }
                    }
                },
                data() {
                    return{
                        dnumber1: this.number1,
                        dnumber2: this.number2
                    }
                },
                methods: {
                    childNum1Input(event) {
                        this.dnumber1 = event.target.value;
                        // 要小写，大写可能出错
                        this.$emit('child-num1-change', event.target.value)
                        // this.$emit('childNum1Change', event.target.value)
                    },
                    childNum2Input(event) {
                        this.dnumber2 = event.target.value;
                        // this.$emit('child-num2-change', event.target.value)
                        this.$emit('child-num2-change', event.target.value)
                    }
                }
            }
        },
        methods: {
            parentNum1Change(value){
                console.log(111)
                this.num1 = parseInt(value);
            },
            parentNum2Change(value){
                this.num2 = parseInt(value);
            }
        }
    })
</script>
</body>
</html>
